home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / liboctave / dbleSCHUR.cc < prev    next >
C/C++ Source or Header  |  1996-03-03  |  3KB  |  152 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if defined (__GNUG__)
  24. #pragma implementation
  25. #endif
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #include <iostream.h>
  32.  
  33. #include "dbleSCHUR.h"
  34. #include "f77-fcn.h"
  35. #include "lo-error.h"
  36. #include "mx-inlines.cc"
  37.  
  38. extern "C"
  39. {
  40.   int F77_FCN (dgeesx, DGEESX) (const char*, const char*,
  41.                 SCHUR::select_function, const char*,
  42.                 const int&, double*, const int&,
  43.                 int&, double*, double*, double*,
  44.                 const int&, double&, double&, double*,
  45.                 const int&, int*, const int&, int*,
  46.                 int&, long, long);
  47. }
  48.  
  49. static int
  50. select_ana (const double& a, const double&)
  51. {
  52.    return (a < 0.0);
  53. }
  54.  
  55. static int
  56. select_dig (const double& a, const double& b)
  57. {
  58.   return (hypot (a, b) < 1.0);
  59. }
  60.  
  61. int
  62. SCHUR::init (const Matrix& a, const string& ord)
  63. {
  64.   int a_nr = a.rows ();
  65.   int a_nc = a.cols ();
  66.  
  67.   if (a_nr != a_nc)
  68.     {
  69.       (*current_liboctave_error_handler) ("SCHUR requires square matrix");
  70.       return -1;
  71.     }
  72.  
  73.   char jobvs = 'V';
  74.   char sense = 'N';
  75.   char sort = 'N';
  76.  
  77.   char ord_char = ord.empty () ? 'U' : ord[0];
  78.  
  79.   if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd')
  80.     sort = 'S';
  81.  
  82.   if (ord_char == 'A' || ord_char == 'a')
  83.     selector = select_ana;
  84.   else if (ord_char == 'D' || ord_char == 'd')
  85.     selector = select_dig;
  86.   else
  87.     selector = 0;
  88.  
  89.   int n = a_nc;
  90.   int lwork = 8 * n;
  91.   int liwork = 1;
  92.   int info;
  93.   int sdim;
  94.   double rconde;
  95.   double rcondv;
  96.  
  97.   schur_mat = a;
  98.   unitary_mat.resize (n, n);
  99.  
  100.   double *s = schur_mat.fortran_vec ();
  101.   double *q = unitary_mat.fortran_vec ();
  102.  
  103.   Array<double> wr (n);
  104.   double *pwr = wr.fortran_vec ();
  105.  
  106.   Array<double> wi (n);
  107.   double *pwi = wi.fortran_vec ();
  108.  
  109.   Array<double> work (lwork);
  110.   double *pwork = work.fortran_vec ();
  111.  
  112.   // These are not referenced for the non-ordered Schur routine.
  113.  
  114.   Array<int> bwork;
  115.   Array<int> iwork;
  116.  
  117.   if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd')
  118.     {
  119.       bwork.resize (n);
  120.       iwork.resize (liwork);
  121.     }
  122.  
  123.   int *pbwork = bwork.fortran_vec ();
  124.   int *piwork = iwork.fortran_vec ();
  125.  
  126.  
  127.   F77_XFCN (dgeesx, DGEESX, (&jobvs, &sort, selector, &sense, n, s,
  128.                  n, sdim, pwr, pwi, q, n, rconde, rcondv,
  129.                  pwork, lwork, piwork, liwork, pbwork,
  130.                  info, 1L, 1L));
  131.  
  132.   if (f77_exception_encountered)
  133.     (*current_liboctave_error_handler) ("unrecoverable error in dgeesx");
  134.  
  135.   return info;
  136. }
  137.  
  138. ostream&
  139. operator << (ostream& os, const SCHUR& a)
  140. {
  141.   os << a.schur_matrix () << "\n";
  142.   os << a.unitary_matrix () << "\n";
  143.  
  144.   return os;
  145. }
  146.  
  147. /*
  148. ;;; Local Variables: ***
  149. ;;; mode: C++ ***
  150. ;;; End: ***
  151. */
  152.